home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / amipop17.zip / POP_CX.C < prev    next >
C/C++ Source or Header  |  1993-09-13  |  3KB  |  155 lines

  1.  
  2. #include "pop.h"
  3.  
  4. struct Library *CxBase;
  5.  
  6. int setupcx(void)
  7. {
  8.  
  9.     CxObj *filter, *sender, *translate;
  10.  
  11.     sprintf(cxname,"AmiPOP(%s)",username);
  12.     newbroker.nb_Name=cxname;
  13.  
  14.     sprintf(cxdesc,"POP Client for '%s'",username);
  15.     newbroker.nb_Descr=cxdesc;
  16.  
  17.     if (CxBase = OpenLibrary("commodities.library", 37L) )
  18.     {
  19.         if (amipop_mp = CreateMsgPort() )
  20.         {
  21.             newbroker.nb_Port = amipop_mp;
  22.             broker = CxBroker(&newbroker, NULL);
  23.             if ( broker == NULL  )
  24.             {
  25.                 closecx();
  26.                 return(0);
  27.             }
  28.  
  29.             if (hotkey)
  30.             {
  31.                 if ( filter=CxFilter(hotkey) )
  32.                 {
  33.                     AttachCxObj(broker, filter);
  34.                     if ( sender=CxSender(amipop_mp, EVT_HOTKEY) )
  35.                     {
  36.                         AttachCxObj(filter,sender);
  37.                         if (translate= CxTranslate(NULL))
  38.                         {
  39.                             AttachCxObj(filter,translate);
  40.                             ActivateCxObj(broker, 1L);
  41.                         }
  42.                         else
  43.                         {
  44.                             closecx();
  45.                             return(0);
  46.                         }
  47.                     }
  48.                     else
  49.                     {
  50.                         closecx();
  51.                         return(0);
  52.                     }
  53.                 }
  54.                 else
  55.                 {
  56.                     closecx();
  57.                     return(0);
  58.                 }
  59.             }
  60.  
  61.             cxsigflag = 1L << amipop_mp->mp_SigBit;
  62.         }
  63.         else
  64.         {
  65.             closecx();
  66.             return(0);
  67.         }
  68.  
  69.         return(1);
  70.     }
  71.     else
  72.     {
  73.         closecx();
  74.         return(0);
  75.     }
  76. }
  77.  
  78. void closecx( void )
  79. {
  80.  
  81.     CxMsg *msg;
  82.  
  83.     if (amipop_mp)
  84.     {
  85.              if (broker) DeleteCxObj(broker);
  86.  
  87.         while (msg = (CxMsg *)GetMsg(amipop_mp) )
  88.         {
  89.             ReplyMsg( (struct Message *)msg );
  90.         }
  91.  
  92.         DeleteMsgPort(amipop_mp);
  93.     }
  94.  
  95.     if (CxBase) CloseLibrary(CxBase);
  96.  
  97.     cxsigflag=NULL;
  98.     amipop_mp=NULL;
  99.     CxBase=NULL;
  100.     broker=NULL;
  101. }
  102.  
  103. int docx (void)
  104. {
  105.     CxMsg *msg;
  106.     ULONG msgid;
  107.     int keepgoing=1;
  108.  
  109.     while (msg = (CxMsg *)GetMsg(amipop_mp) )
  110.     {
  111.         msgid = CxMsgID(msg);
  112.         ReplyMsg( (struct Message *)msg);
  113.  
  114.         switch(msgid)
  115.         {
  116.             case CXCMD_DISABLE:
  117.                 checkper=FALSE;
  118.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_TIME], Project0Wnd, NULL, GA_Disabled, !checkper,TAG_END);
  119.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_CRONCHECK], Project0Wnd, NULL, GTCB_Checked, checkper,TAG_END);
  120.  
  121.                 break;
  122.  
  123.             case CXCMD_ENABLE:
  124.                 checkper=TRUE;
  125.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_TIME], Project0Wnd, NULL, GA_Disabled, !checkper,TAG_END);
  126.                 GT_SetGadgetAttrs(Project0Gadgets[GD_MYGAD_CRONCHECK], Project0Wnd, NULL, GTCB_Checked, checkper,TAG_END);
  127.  
  128.                 break;
  129.  
  130.             case CXCMD_KILL:
  131.                 keepgoing=0;
  132.                 break;
  133.  
  134.             case CXCMD_APPEAR:
  135.                 if (winop==FALSE) openup();
  136.                 break;
  137.  
  138.             case CXCMD_DISAPPEAR:
  139.                 if (winop) closedown();
  140.                 break;
  141.  
  142.             case CXCMD_UNIQUE:
  143.                 if (winop==FALSE) openup();
  144.                 doreq("AmiPOP already active\nfor this user","Oops");
  145.                 break;
  146.  
  147.             case EVT_HOTKEY:
  148.                 if (winop==FALSE) openup();
  149.                 break;
  150.         }
  151.     }
  152.     return(keepgoing);
  153. }
  154.  
  155.